# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union, List
from pydantic import BaseModel, Field
from fastapi import Query


class DocsPromptSearchIn(BaseModel):
    """ 模式搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    name: Union[str, None] = Query(default=None, description="文件名称")


class DocsPromptDetailIn(BaseModel):
    """ 模式详情参数 """
    id: int = Query(..., gt=0, description="ID")


class DocsPromptAddIn(BaseModel):
    """ 模式新增参数 """
    icon: str = Field(..., max_length=250, description="图标")
    name: str = Field(..., max_length=100, description="名称")
    intro: str = Field(..., max_length=200, description="简介")
    sort: int = Field(default=0, ge=0, description="排序")
    is_disable: int = Field(..., ge=0, le=1, description="是否禁用: [0=否, 1=是]")
    abstract_conf: List[dict] = Field(..., description="摘要模型配置")
    dialogue_conf: dict = Field(..., description="对话模型配置")

    class Config:
        json_schema_extra = {
            "example": {
                "icon": "https://xx.com/storage/9749cbe7beb.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 0,
                "is_disable": 0,
                "abstract_conf": [
                    [{
                        "name": "agent-1",
                        "model": "zhipu:glm-4-long",
                        "prompt": "",
                        "params": {
                            "context_num": 3,
                            "temperature": 0.95
                        }
                    }]
                ],
                "dialogue_conf": {
                    "model": "zhipu:glm-4-long",
                    "prompt": "this is model prompt",
                    "params": {
                        "context_num": 3,
                        "temperature": 0.95
                    }
                }
            }
        }


class DocsPromptEditIn(BaseModel):
    """ 模式编辑参数 """
    id: int = Field(..., description="ID")
    icon: str = Field(..., max_length=250, description="图标")
    name: str = Field(..., max_length=100, description="名称")
    intro: str = Field(..., max_length=200, description="简介")
    sort: int = Field(default=0, ge=0, description="排序")
    is_disable: int = Field(..., ge=0, le=1, description="是否禁用: [0=否, 1=是]")
    abstract_conf: List[dict] = Field(..., description="摘要模型配置")
    dialogue_conf: dict = Field(..., description="对话模型配置")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "icon": "https://xx.com/76f9749cbe7beb.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 0,
                "is_disable": 0,
                "abstract_conf": [
                    [{
                        "name": "agent-1",
                        "model": "zhipu:glm-4-long",
                        "prompt": "",
                        "params": {
                            "context_num": 3,
                            "temperature": 0.95
                        }
                    }]
                ],
                "dialogue_conf": {
                    "model": "zhipu:glm-4-long",
                    "prompt": "this is model prompt",
                    "params": {
                        "context_num": 3,
                        "temperature": 0.95
                    }
                }
            }
        }


class DocsPromptDeleteIn(BaseModel):
    """ 模式删除参数 """
    id: int = Field(..., gt=0, description="ID")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1
            }
        }


"""--------------- Separator ---------------"""


class DocsPromptListVo(BaseModel):
    id: int = Field(description="ID")
    code: str = Field(description="编号")
    icon: str = Field(description="图标")
    name: str = Field(description="名称")
    intro: str = Field(description="简介")
    sort: int = Field(description="排序")
    is_builtin: int = Field(description="系统内置: [0=否, 1=是]")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "23864318",
                "icon": "https://xx.com/static/images/general.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 99,
                "is_builtin": 1,
                "is_disable": 0,
                "create_time": "2024-05-20 13:14:00"
            }
        }


class DocsPromptDetailVo(BaseModel):
    id: int = Field(description="ID")
    code: str = Field(description="编号")
    icon: str = Field(description="图标")
    name: str = Field(description="名称")
    intro: str = Field(description="简介")
    sort: int = Field(description="排序")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    abstract_conf: List[dict] = Field(description="摘要提示词")
    dialogue_conf: dict = Field(description="摘要提示词")

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "code": "23864318",
                "icon": "http://127.0.0.1:8100/static/images/docs_general.png",
                "name": "通用阅读",
                "intro": "综合各种基础阅读场景，快速总结解答",
                "sort": 99,
                "is_disable": 0,
                "abstract_conf": {
                        "model": "zhipu:glm-4-long",
                        "prompt": "this prompt",
                        "params": {
                            "context_num": 3,
                            "temperature": 0.95
                        }
                    },
                "dialogue_conf": [
                    {
                        "name": "概要",
                        "model": "zhipu:glm-4-long",
                        "prompt": "this prompt",
                        "params": {
                            "context_num": 3,
                            "temperature": 0.95
                        }
                    }
                ]
            }
        }
